/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditNannyDlg.java
 *
 * Created on May 8, 2010, 6:04:25 PM
 */
package com.aptech.childcare.gui;

import com.aptech.childcare.buz.ChildcareBuz;
import com.aptech.childcare.entities.Nanny;
import java.awt.Image;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Date;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author BaoTien
 */
public class AddNannyDlg extends javax.swing.JDialog {

    String fileImage = null;
    ChildcareBuz buz = new ChildcareBuz();
    MainFrm main;
    String url = null, path = null;
    Calendar ca = Calendar.getInstance();

    /** Creates new form EditNannyDlg */
    public AddNannyDlg(MainFrm main, boolean modal) {
        super(main, modal);
        this.main = main;
        /**
         *
         */
        ImageIcon icon = new ImageIcon(getClass().getResource("../icon/logo.png"));
        Image image = icon.getImage();
        setIconImage(image);
        /**
         *
         */
        try {
            com.jgoodies.looks.plastic.PlasticLookAndFeel.setCurrentTheme(new com.jgoodies.looks.plastic.theme.ExperienceBlue());
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        cbSex = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        dcBirthday = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        btnSetClass = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtClassID = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        btnAdd = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        lbImage = new javax.swing.JLabel();
        btnGetImage = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        dcStartDate = new com.toedter.calendar.JDateChooser();
        txtCharge = new javax.swing.JTextField();
        txtWorkinghours = new javax.swing.JTextField();

        setTitle("Add Information of Nanny");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jPanel1.setNextFocusableComponent(txtName);
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 255)));
        jPanel2.setLayout(new java.awt.GridBagLayout());

        jLabel3.setText("Sex ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel2.add(jLabel3, gridBagConstraints);

        jLabel6.setText("Name ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel2.add(jLabel6, gridBagConstraints);

        txtName.setColumns(15);
        txtName.setNextFocusableComponent(dcBirthday);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel2.add(txtName, gridBagConstraints);

        cbSex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
        cbSex.setNextFocusableComponent(txtPhone);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(cbSex, gridBagConstraints);

        jLabel4.setText("Birthday ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel2.add(jLabel4, gridBagConstraints);

        dcBirthday.setMinimumSize(new java.awt.Dimension(110, 20));
        dcBirthday.setNextFocusableComponent(cbSex);
        dcBirthday.setPreferredSize(new java.awt.Dimension(110, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel2.add(dcBirthday, gridBagConstraints);

        jLabel7.setText("Phone ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel2.add(jLabel7, gridBagConstraints);

        txtPhone.setColumns(12);
        txtPhone.setNextFocusableComponent(btnSetClass);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel2.add(txtPhone, gridBagConstraints);

        btnSetClass.setText("set");
        btnSetClass.setNextFocusableComponent(btnGetImage);
        btnSetClass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSetClassActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        jPanel2.add(btnSetClass, gridBagConstraints);

        jLabel1.setText("Class ID");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel2.add(jLabel1, gridBagConstraints);

        txtClassID.setColumns(10);
        txtClassID.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel2.add(txtClassID, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel2, gridBagConstraints);

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Add Nanny");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 9, 4);
        jPanel1.add(jLabel15, gridBagConstraints);

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/aptech/childcare/icon/add.png"))); // NOI18N
        btnAdd.setText("Add");
        btnAdd.setMaximumSize(new java.awt.Dimension(85, 25));
        btnAdd.setMinimumSize(new java.awt.Dimension(85, 25));
        btnAdd.setNextFocusableComponent(btnCancel);
        btnAdd.setPreferredSize(new java.awt.Dimension(85, 25));
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        jPanel7.add(btnAdd);

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/aptech/childcare/icon/Cancel-2-16x16.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.setNextFocusableComponent(txtName);
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        jPanel7.add(btnCancel);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 11, 10);
        jPanel1.add(jPanel7, gridBagConstraints);

        jPanel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 255)));
        jPanel6.setLayout(new java.awt.GridBagLayout());

        lbImage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbImage.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lbImage.setMaximumSize(new java.awt.Dimension(100, 100));
        lbImage.setMinimumSize(new java.awt.Dimension(100, 100));
        lbImage.setPreferredSize(new java.awt.Dimension(100, 100));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(7, 8, 7, 8);
        jPanel6.add(lbImage, gridBagConstraints);

        btnGetImage.setText("Get Image");
        btnGetImage.setNextFocusableComponent(txtAddress);
        btnGetImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGetImageActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(7, 8, 7, 8);
        jPanel6.add(btnGetImage, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel6, gridBagConstraints);

        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 255)));
        jPanel5.setMinimumSize(new java.awt.Dimension(300, 180));
        jPanel5.setPreferredSize(new java.awt.Dimension(300, 180));
        jPanel5.setLayout(new java.awt.GridBagLayout());

        jLabel10.setText("Start Date");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel10, gridBagConstraints);

        jLabel11.setText("Email");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel11, gridBagConstraints);

        jLabel12.setText("Charge");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel12, gridBagConstraints);

        jLabel13.setText("Workinghours");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel13, gridBagConstraints);

        jLabel14.setText("Address     ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel14, gridBagConstraints);

        txtAddress.setColumns(15);
        txtAddress.setMinimumSize(new java.awt.Dimension(200, 20));
        txtAddress.setNextFocusableComponent(txtEmail);
        txtAddress.setPreferredSize(new java.awt.Dimension(200, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtAddress, gridBagConstraints);

        txtEmail.setColumns(15);
        txtEmail.setMinimumSize(new java.awt.Dimension(200, 20));
        txtEmail.setNextFocusableComponent(txtCharge);
        txtEmail.setPreferredSize(new java.awt.Dimension(200, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtEmail, gridBagConstraints);

        dcStartDate.setMinimumSize(new java.awt.Dimension(120, 20));
        dcStartDate.setNextFocusableComponent(btnAdd);
        dcStartDate.setPreferredSize(new java.awt.Dimension(126, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(dcStartDate, gridBagConstraints);

        txtCharge.setColumns(15);
        txtCharge.setEditable(false);
        txtCharge.setNextFocusableComponent(txtWorkinghours);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtCharge, gridBagConstraints);

        txtWorkinghours.setColumns(15);
        txtWorkinghours.setNextFocusableComponent(dcStartDate);
        txtWorkinghours.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtWorkinghoursKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtWorkinghours, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel5, gridBagConstraints);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        try {
            // TODO add your handling code here:
            Nanny na = new Nanny();
            if (txtName.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter Name");
                txtName.requestFocus();
                return;
            }
            if (txtClassID.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,set Class ID");
                txtClassID.requestFocus();
                return;
            }
            if (txtWorkinghours.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter working hours");
                txtWorkinghours.requestFocus();
                return;
            }
            if (txtEmail.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter Email");
                txtEmail.requestFocus();
                return;
            }
            String strEmail = "\\w+(\\.\\w+)*@\\w+(\\.\\w+)+";
            if (txtEmail.getText().length() != 0) {
                if (!Pattern.matches(strEmail, txtEmail.getText())) {
                    JOptionPane.showMessageDialog(this, "Email no match!");
                    txtEmail.requestFocus();
                    txtEmail.selectAll();
                    return;
                }
            }
            if (txtPhone.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter Phone");
                txtPhone.requestFocus();
                return;
            }
            String strPhone = "[0-9]{7,11}";
            if (txtPhone.getText().length() != 0) {
                if (!Pattern.matches(strPhone, txtPhone.getText())) {
                    JOptionPane.showMessageDialog(this, "Phone number must be greater than 7 characters and numbers.");
                    txtEmail.requestFocus();
                    txtEmail.selectAll();
                    return;
                }
            }
            ca.setTime(dcStartDate.getDate());
            Date startDate = new Date(ca.getTimeInMillis());
            if (dcStartDate.getDate() != null) {
                if (dcStartDate.getCalendar().getTime().after(startDate)) {
                    JOptionPane.showMessageDialog(this, "Start Date < today");
                    dcStartDate.setDate(null);
                    dcStartDate.requestFocus();
                    return;
                }
            }
            ca.setTime(dcBirthday.getDate());
            Date birthDate = new Date(ca.getTimeInMillis());
            if (dcBirthday.getDate() != null) {
                if (dcBirthday.getCalendar().getTime().after(birthDate)) {
                    JOptionPane.showMessageDialog(this, "Birthday Date < today");
                    dcBirthday.setDate(null);
                    dcBirthday.requestFocus();
                    return;
                }
            }
            na.setFullName(txtName.getText());
            na.setBirthday(birthDate);
            na.setSex(cbSex.getSelectedItem().toString());
            na.setPhone(txtPhone.getText());
            na.setClassID(Integer.parseInt(txtClassID.getText()));
            na.setPathImage(fileImage);
            na.setAddress(txtAddress.getText());
            na.setEmail(txtEmail.getText());
            na.setCharge(Float.parseFloat(txtCharge.getText()));
            na.setWorkinghours(Integer.parseInt(txtWorkinghours.getText()));
            na.setStartDay(startDate);
            if (buz.createNanny(na)) {
                JOptionPane.showMessageDialog(this, buz.nadao.getLastError());
                this.dispose();
            } else {
                JOptionPane.showMessageDialog(this, buz.nadao.getLastError());
            }
        } catch (IOException ex) {
            Logger.getLogger(AddNannyDlg.class.getName()).log(Level.SEVERE, null, ex);
        }



}//GEN-LAST:event_btnAddActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        txtName.setText("");
        txtPhone.setText("");
        txtAddress.setText("");
        txtEmail.setText("");
        lbImage.setIcon(null);
}//GEN-LAST:event_btnCancelActionPerformed

    @SuppressWarnings("static-access")
    private void btnGetImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGetImageActionPerformed
        // TODO add your handling code here:
        JFileChooser jf = new JFileChooser("c:\\");
        int read = jf.showOpenDialog(null);
        if (read == jf.APPROVE_OPTION) {
            url = String.valueOf(jf.getSelectedFile());
            path = url.substring(0, url.indexOf("\\"));
            fileImage = url.substring(url.lastIndexOf("\\"));
            try {
                FileInputStream fin = new FileInputStream(url);
                FileOutputStream fout = new FileOutputStream("image\\" + fileImage);
                int data = 0;
                while ((data = fin.read()) != -1) {
                    fout.write(data);
                }
                fout.close();
                fin.close();
            } catch (IOException ex) {
                Logger.getLogger(AddNannyDlg.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            return;
        }
        String paths = "image\\" + fileImage;
        lbImage.setIcon(new javax.swing.ImageIcon(paths));

}//GEN-LAST:event_btnGetImageActionPerformed

    private void btnSetClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSetClassActionPerformed
        try {
            // TODO add your handling code here:
            ViewClassDlg viewcl = new ViewClassDlg(this, true);
            viewcl.setVisible(true);
        } catch (IOException ex) {
            Logger.getLogger(AddNannyDlg.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnSetClassActionPerformed

    private void txtWorkinghoursKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtWorkinghoursKeyReleased
        // TODO add your handling code here:

        txtCharge.setText(String.valueOf(Integer.parseInt(txtWorkinghours.getText()) * 12));

    }//GEN-LAST:event_txtWorkinghoursKeyReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    AddNannyDlg dialog = new AddNannyDlg(new MainFrm(), true);
                    dialog.setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(AddNannyDlg.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnGetImage;
    private javax.swing.JButton btnSetClass;
    private javax.swing.JComboBox cbSex;
    private com.toedter.calendar.JDateChooser dcBirthday;
    private com.toedter.calendar.JDateChooser dcStartDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JLabel lbImage;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtCharge;
    protected javax.swing.JTextField txtClassID;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtWorkinghours;
    // End of variables declaration//GEN-END:variables
}
